package com.example.dklauncherdemo.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dklauncherdemo.R;
import com.example.dklauncherdemo.util.AppInfo;

public class DeskTopGridViewBaseAdapter extends BaseAdapter {

	Context context;
	List<AppInfo> appInfos = new ArrayList<AppInfo>();

	public DeskTopGridViewBaseAdapter(List<AppInfo> appInfos, Context context) {
		this.appInfos = appInfos;
		this.context = context;
	}

	@Override
	public int getCount() {
		return appInfos.size();
	}

	@Override
	public Object getItem(int position) {
		return appInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.desktop_gridview_item, null);
			holder = new Holder();
			holder.ico = (ImageView) convertView.findViewById(R.id.iv);
			holder.Name = (TextView) convertView.findViewById(R.id.tv);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}

		holder.ico.setImageDrawable(appInfos.get(position).getIco());
		holder.Name.setText(appInfos.get(position).getName());

		return convertView;
	}

	static class Holder {
		ImageView ico;
		TextView Name;

	}
}
